//
// Created by h00422988 on 2021/8/20.
//

#ifndef MEDIAPIPELINE_AUDIO_TRACK_SINK_PLUGIN_H
#define MEDIAPIPELINE_AUDIO_TRACK_SINK_PLUGIN_H
#ifdef __ANDROID__

#include "plugin/common/plugin_audio_tags.h"
#include "interface/audio_sink_plugin.h"
#include "audio_track_proxy.h"

namespace OHOS {
namespace Media {
namespace Plugin {
class AudioTrackSinkPlugin :public AudioSinkPlugin, public std::enable_shared_from_this<AudioTrackSinkPlugin>{
public:
    explicit AudioTrackSinkPlugin(std::string name);
    ~AudioTrackSinkPlugin() override = default;

    Status Init() override;

    Status Deinit() override;

    Status Prepare() override;

    Status Reset() override;

    Status Start() override;

    Status Stop() override;

    bool IsParameterSupported(Tag tag) override;

    Status GetParameter(Tag tag, ValueType &value) override;

    Status SetParameter(Tag tag, const ValueType &value) override;

    Status GetState(State &state);

    std::shared_ptr<Allocator> GetAllocator() override;

    Status SetCallback(const std::shared_ptr<Callback> &cb) override;

    Status GetMute(bool &mute) override;

    Status SetMute(bool mute) override;

    Status GetVolume(float &volume) override;

    Status SetVolume(float volume) override;

    Status GetSpeed(float &speed) override;

    Status SetSpeed(float speed) override;

    Status Pause() override;

    Status Resume() override;

    Status GetLatency(uint64_t &ms) override;

    Status GetFrameSize(size_t &size) override;

    Status GetFrameCount(uint32_t &count) override;

    Status Write(const std::shared_ptr<Buffer> &input) override;

    Status Flush() override;

private:
    std::string aliasName_{};
    size_t avFrameSize_{};
    int32_t channels_{-1};
    int32_t sampleRate_{-1};
    int32_t samplesPerFrame_{-1};
    uint64_t channelMask_{0};
    AudioSampleFormat sampleFormat_{AudioSampleFormat::U8};
    std::shared_ptr<AudioTrackProxy> audioTrack_;
};
}
}
}
#endif

#endif //MEDIAPIPELINE_AUDIO_TRACK_SINK_PLUGIN_H
